package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    // 插入订单
    void insert(Orders orders);

    //根据订单号查询订单
    @Select("select * from orders where number = #{orderNumber} and user_id = #{userId}")
    Orders getByNumberAndUserId(String orderNumber,Long userId);

    // 更新订单信息
    void update(Orders orders);

    // 更新数据库订单状态
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{checkoutTime} where number = #{orderNumber}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkoutTime, String orderNumber);
    // 查询历史订单
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    // 根据id查询订单基本信息
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    // 根据订单状态查询订单数量
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    // 根据订单状态和下单时间查询订单
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status,LocalDateTime orderTime);

    // 计算时间范围内的营业额
    Double sumByMap(Map map);

    // 计算时间范围内的订单
    Integer countByMap(Map map);

    // 统计指定时间区间内的销量排名前十
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin,LocalDateTime end);
}
